# 字符串操作

#成员运算符(in, not in)
# s = "hello world"
# print("hello" in s)
# print("world" not in s)

#连接运算符(+)
# s1 = "hello"
# s2 = "world"
# result = s1 + " " + s2
# print(result)

# 重复运算符(*)
# s = "hello"
# result = s * 3
# print(result)

#索引和切片
s = "hello world"
# print(s[0])
# print(s[-1])
# print(s[0:5])
# print(s[:5])
# print(s[6:])
print(s[1:5:3])

# 大小写转换
# s = "Hello World"
# print(s.lower())
# print(s.upper())
# print(s.title())
# print(s.swapcase())

# 去除空白字符
# s = " hello world"
# print(s.strip())
# print(s.lstrip())
# print(s.rstrip())

# 替换子字符串
# s = "hello world"
# print(s.replace("world", "Python"))

# 分割字符串
# s = "apple,bananas,cherry"
# fruits = s.split(",")
# print(fruits)

#查找子字符串
# s = "hello world"
# print(s.find("world"))
# print(s.index("world"))
# print(s.find("Python"))

#判断字符串类型
# s = "hello world"
# print(s.startswith("hello"))
# print(s.endswith("world"))

# 字符串长度
# s = "hello"
# print(len(s))

# 字符串格式化
# name = "gaoluchuan"
# age = 25
# print("My name is {} and I am {} years old.".format(name,age))
# print(f"My name is {name} and I am {age} years old.")

# 字符串对齐
# s = "hello"
# print(s.ljust(10, "-"))
# print(s.rjust(10, "-"))
# print(s.center(10, "-"))

#字符串转义
# s = "Hello\nWorld"
# print(s)
# s2 = "He said, \"Hello!\""
# print(s2)